package com.ruoyi.travel.service.impl;

import java.util.Collections;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.travel.mapper.TravelScheduleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.travel.mapper.TravelScheduleContentMapper;
import com.ruoyi.travel.domain.TravelScheduleContent;
import com.ruoyi.travel.service.ITravelScheduleContentService;

@Service
public class TravelScheduleContentServiceImpl implements ITravelScheduleContentService
{
    @Autowired
    private TravelScheduleContentMapper travelScheduleContentMapper;
    @Autowired
    private TravelScheduleMapper travelScheduleMapper;
    /**
     * 查询行程内容
     *
     * @param scheduleContentId 行程内容主键
     * @return 行程内容
     */
    @Override
    public List<TravelScheduleContent> selectTravelScheduleContentByScheduleContentId(Long scheduleContentId)
    {
        return travelScheduleContentMapper.selectTravelScheduleContentByScheduleContentId(scheduleContentId);
    }

    /**
     * 查询行程内容列表
     *
     * @param travelScheduleContent 行程内容
     * @return 行程内容
     */
    @Override
    public List<TravelScheduleContent> selectTravelScheduleContentList(TravelScheduleContent travelScheduleContent)
    {
        return travelScheduleContentMapper.selectTravelScheduleContentList(travelScheduleContent);
    }

    /**
     * 新增行程内容
     *
     * @param travelScheduleContent 行程内容
     * @return 结果
     */
    @Override
    public void insertTravelScheduleContent(List<TravelScheduleContent> travelScheduleContent)
    {
        //更新行程内容的时候也要更新行程表的更新时间
        travelScheduleMapper.selectTravelScheduleByScheduleId(travelScheduleContent.get(0).getScheduleId()).setUpdateTime(DateUtils.getNowDate());
        travelScheduleMapper.updateTravelSchedule(travelScheduleMapper.selectTravelScheduleByScheduleId(travelScheduleContent.get(0).getScheduleId()));
        for(TravelScheduleContent tsc:travelScheduleContent){

            tsc.setCreateTime(DateUtils.getNowDate());
            travelScheduleContentMapper.insertTravelScheduleContent(tsc);
        }
    }

    /**
     * 修改行程内容
     *
     * @param travelScheduleContent 行程内容
     * @return 结果
     */
    @Override
    public int updateTravelScheduleContent(TravelScheduleContent travelScheduleContent)
    {
        travelScheduleContent.setUpdateTime(DateUtils.getNowDate());
        return travelScheduleContentMapper.updateTravelScheduleContent(travelScheduleContent);
    }


    /**
     * 删除行程内容信息
     *
     * @param scheduleId 行程内容主键
     * @return 结果
     */

    @Override
    public int deleteTravelScheduleContentByScheduleId(Long scheduleId) {
        return travelScheduleContentMapper.deleteTravelScheduleContentByScheduleId(scheduleId);
    }

}
